# coding:utf-8
from selenium import webdriver

driver = webdriver.Chrome('./chromedriver.exe')


def get_baidu_cookies(url="https://www.baidu.com/"):
    "通过模拟浏览器获取百度的Cookies"

    driver.get(url)

    cookie = driver.get_cookies()
    print(cookie)

    # jsonCookies = json.dumps(cookie)
    # cookie=str(cookie)

    print(cookie)

    # 简版cookies
    # cookie = [item["name"] + "=" + item["value"] for item in cookie if item['name']=="BIDUPSID"]
    cookie = [item["name"] + "=" + item["value"] for item in cookie]

    cookiestr = '; '.join(item for item in cookie)
    print(cookiestr)

    return cookiestr


if __name__ == '__main__':
    get_baidu_cookies()
